//
//  DeallocObject.m
//  XPhoto
//
//  Created by sentinel on 2020/3/26.
//  Copyright © 2020 baboy. All rights reserved.
//

#import "BKObserveDeallocObject.h"

@interface BKObserveDeallocObject()
@property (nonatomic, copy ) void(^deallocBlock)(void);
@end

@implementation BKObserveDeallocObject
- (instancetype)initWithDellocBlock:(void(^)(void))dellocBlock{
    self = [super init];
    if (self) {
        _deallocBlock = dellocBlock;
    }
    return self;
}

+ (instancetype)objectWithDeallocBlock:(void(^)(void))deallocBlock{
    return [[self alloc] initWithDellocBlock:deallocBlock];
}

- (void) observeValueForKeyPath:(NSString *)keyPath
                       ofObject:(id)object
                         change:(NSDictionary<NSKeyValueChangeKey,id> *)change
                        context:(void *)context{
    if ( self.delegateObserveBlock) {
        self.delegateObserveBlock(keyPath, object, change, context);
    }
}
- (void)dealloc{
    if (self.deallocBlock) {
        self.deallocBlock();
    }
}
@end
